package myStack;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-05-27
 * Time:16:14
 */
public class MyStack {
    private int[] elem;
    private int usedSize;

    public MyStack() {
        this.elem = new int[5];
        this.usedSize = 0;
    }

    public boolean isFull(){
        return this.usedSize==this.elem.length;
    }
    public void myPush(int data){
        if(this.isFull()){
            Arrays.copyOf(this.elem,this.elem.length*2);
        }
        this.elem[this.usedSize]=data;
        this.usedSize++;
    }
    public int myPop(){
        if(this.usedSize==0){
            System.out.println("栈为空！");
            throw new RuntimeException();
        }
        int ret=this.elem[usedSize-1];
        this.elem[usedSize-1]=0;
        this.usedSize--;
        return ret;
    }

    public int myPeek(){
        if(this.usedSize==0){
            System.out.println("栈为空！");
            throw new RuntimeException();
        }
        return this.elem[usedSize-1];
    }
    public boolean myIsEmpty(){
        return this.usedSize==0;
    }
}
